//
//  MyViewController.m
//  BigTyre
//
//  Created by 田涛 on 2017/3/15.
//  Copyright © 2017年 Lemon. All rights reserved.
//

#import "MyViewController.h"
#import <ShareSDK/ShareSDK.h>
#import "MyCommon.h"
@interface MyViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    
    NSArray * titleArr;//单元格标题

}
@property(nonatomic,strong)UITableView * table;
@property(nonatomic,strong)NSArray * colorarr;
@end

@implementation MyViewController
-(void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden=NO;
    self.navigationController.navigationBar.hidden=YES;
        [_table reloadData];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
//    self.view.backgroundColor=[UIColor colorWithRed:117/255.0 green:211/255.0 blue:186/255.0 alpha:1.0];
    //底层图片
    UIImageView * image=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    image.image=[UIImage imageNamed:@"背景.jpeg"];
    image.userInteractionEnabled=YES;
    [self.view addSubview:image];
    //左上角设置按钮
    UIButton * btSet=[[UIButton alloc]initWithFrame:CGRectMake(20, 40, 30, 30)];
    [btSet setBackgroundImage:[UIImage imageNamed:@"设置"] forState:0];
    [btSet addTarget:self action:@selector(clickSet) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btSet];
    
    //用户头像
    UIButton * button=[UIButton buttonWithType:UIButtonTypeCustom];
    button.frame=CGRectMake((self.view.frame.size.width)/2-50, 100, 100, 100);
    button.layer.masksToBounds=YES;
    button.layer.cornerRadius=50;
    button.backgroundColor=[UIColor cyanColor];
    [button setBackgroundImage:[UIImage imageNamed:@"头像"] forState:0];
    [button addTarget:self action:@selector(SkipSignInView) forControlEvents:UIControlEventTouchUpInside];
    [image addSubview:button];
    
    //表格
    _table=[[UITableView alloc]initWithFrame:CGRectMake(0,self.view.frame.size.height-590, self.view.frame.size.width, 580) style:UITableViewStyleGrouped];

//    [_table registerNib:[UINib nibWithNibName:@"MyCell1" bundle:nil] forCellReuseIdentifier:@"aaaaa"];
    _table.userInteractionEnabled=YES;
    _table.backgroundColor = [UIColor clearColor];
    _table.contentInset=UIEdgeInsetsMake(100, 0, 0, 0);
    _table.delegate=self;
    _table.dataSource=self;
    [self.view addSubview:_table];
    //登陆/注册按钮
     _button2=[[UIButton alloc]initWithFrame:CGRectMake((self.view.frame.size.width)/2-50, 220, 100, 30)];
    [_button2 setTitle:@"登录 / 注册" forState:0];
    [_button2 setTintColor:[UIColor whiteColor]];
    [_button2 addTarget:self action:@selector(SkipSignInView2) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_button2];
    
    //表格颜色数组
    _colorarr=@[[UIColor colorWithRed:253/255.0 green:101/255.0 blue:65/255.0 alpha:1.0],
        [UIColor colorWithRed:253/255.0 green:133/255.0 blue:68/255.0 alpha:1.0],
        [UIColor colorWithRed:253/255.0 green:160/255.0 blue:89/255.0 alpha:1.0],
        [UIColor colorWithRed:253/255.0 green:178/255.0 blue:82/255.0 alpha:1.0],
        [UIColor colorWithRed:185/255.0 green:195/255.0 blue:121/255.0 alpha:1.0],
        [UIColor colorWithRed:152/255.0 green:202/255.0 blue:151/255.0 alpha:1.0],
        [UIColor colorWithRed:117/255.0 green:211/255.0 blue:186/255.0 alpha:1.0]];
}
-(void)clickSet
{
     MysetViewController* set=[[MysetViewController alloc]init];
    [self.navigationController pushViewController:set animated:NO];
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if ([scrollView isEqual:_table]) {
//        NSLog(@"%f",_table.contentOffset.y);
        if (_table.contentOffset.y  >-62) {
            _button2.hidden=YES;
        }
        else{
            _button2.hidden=NO;
        }
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 75;

}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 7;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   UITableViewCell *  cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    //单元格标题
  titleArr=@[@"我的资产",@"全部订单",@"购物清单",@"我的收藏",@"我的关注",@"我的分享",@"意见反馈",];
    cell.textLabel.textColor =[UIColor whiteColor];
    cell.backgroundColor=_colorarr[indexPath.row];
    cell.textLabel.text=titleArr[indexPath.row];
    cell.textLabel.font=[UIFont systemFontOfSize:20];
    cell.imageView.image=[UIImage imageNamed:@"动态"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.layer.cornerRadius = 10;
    cell.layer.masksToBounds = YES;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"-----");
    UITableViewCell* CellAtIndex = [tableView cellForRowAtIndexPath:indexPath];
    CGRect frame2 = CellAtIndex.frame;
    frame2.size.height += 10;
    [CellAtIndex setFrame:frame2];
    //点击单元格滚动到视图中央
    [tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section] atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
    //定时  一段时间后开始跳转
    [NSTimer scheduledTimerWithTimeInterval:0.4 target:self selector:@selector(pushSelected:) userInfo:nil repeats:NO];
}
- (void)pushSelected:(NSTimer *)timmer{
    //取消定时器
    [timmer invalidate];
    MySelectedViewController * selected=[[MySelectedViewController alloc]init];
    [self.navigationController pushViewController:selected animated:NO];
}
-(void)SkipSignInView
{
    MySigninViewController * signin=[[MySigninViewController alloc]init];
    [self.navigationController pushViewController:signin animated:YES];
}
-(void)SkipSignInView2
{
    NSLog(@"========");
    MySigninViewController * signin=[[MySigninViewController alloc]init];
    [self.navigationController pushViewController:signin animated:YES];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
